package cevent.source.cloudcenter.business.controller.client;/**
 * Created by Cevent on 2021/8/3.
 */

import cevent.source.cloudcenter.server.dto.GuestBookDto;
import cevent.source.cloudcenter.server.dto.ResponseDataDto;
import cevent.source.cloudcenter.server.service.GuestBookService;
import cevent.source.cloudcenter.server.util.ValidatorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author cevent
 * @description 客户端留言接口
 * @date 2021/8/3 14:34
 */
@RestController
@RequestMapping("/client/guestBook")
public class ClientGuestBookController {
    private static final Logger LOG= LoggerFactory.getLogger(ClientGuestBookController.class);
    public static final String BUSINESS_NAME="客户端留言接口";

    @Resource
    private GuestBookService guestBookService;

    //客户端发送留言
    @PostMapping("/send")
    public ResponseDataDto sendGuestBook(@RequestBody GuestBookDto guestBookDto){
        ResponseDataDto responseData=new ResponseDataDto();
        ValidatorUtil.requiredEmpty(guestBookDto.getMemberId(), "会员未登录，会员名");
        ValidatorUtil.requiredEmpty(guestBookDto.getEmployeeId(), "会员未登录，会员名");
        guestBookService.save(guestBookDto);
        responseData.setResponseData(guestBookDto);
        return responseData;
    }

    @PostMapping("get/{memberId}")
    public ResponseDataDto getGuestBookByMemberId(@PathVariable String memberId){
        ResponseDataDto responseData=new ResponseDataDto();
        responseData.setResponseData(guestBookService.getGuestBookByMemberId(memberId));

        return responseData;
    }

    @DeleteMapping("/del/{uniId}")
    public ResponseDataDto del(@PathVariable String uniId) {
        LOG.info("传入的guestBook uniId：{}", uniId);
        ResponseDataDto responseData = new ResponseDataDto();
        guestBookService.delete(uniId);
        return responseData;
    }
    @DeleteMapping("/delBatch/{uniId}")
    public ResponseDataDto delBatch(@PathVariable String uniId) {
        LOG.info("传入批量删除的guestBook uniId（父ID）：{}", uniId);
        ResponseDataDto responseData = new ResponseDataDto();
        guestBookService.deleteBatch(uniId);
        return responseData;
    }
    //保存留言/回复
    @PostMapping("/save")
    public ResponseDataDto save(@RequestBody GuestBookDto guestBookDto) {
        LOG.info("传入的guestBook DTO：{}", guestBookDto);

        ValidatorUtil.requiredEmpty(guestBookDto.getMemberId(), "会员ID");
        ValidatorUtil.requiredEmpty(guestBookDto.getEmployeeId(), "员工ID");
        ResponseDataDto responseData = new ResponseDataDto();
        guestBookService.save(guestBookDto);
        responseData.setResponseData(guestBookDto);
        return responseData;
    }
}
